﻿@model IEnumerable<ESupervision.Models.Document>
@using Microsoft.AspNet.Identity;
@{
    ViewBag.Title = "Index";
}

<br />
<style>
    .hide {
        display: none;
    }
</style>

<p>
    @Html.ActionLink(" Create New", "Create", "Document", null, new { @class = "btn btn-info  glyphicon glyphicon-plus " })
    @*@Html.ActionLink("Create New", "Create")*@
</p>
<div class="panel panel-success">
    <div class="panel-heading">
        <h3 class="panel-title" id="panel-title">Information Attachement File<a class="anchorjs-link" href="#panel-title"><span class="anchorjs-icon"></span></a></h3>
    </div>
    <div style="padding:10px;">
        @using (Html.BeginForm())
        {
            <p>
                Find by Filename: @Html.TextBox("SearchString")
                <button class="btn btn-warning btn-sm" type="submit"><span class="glyphicon glyphicon-search " /> Search</button>
            </p>
        }
    </div>

    <div class=" table-responsive">
        <table class="table table-hover ">
            <tr class="info">
                <th>
                    @Html.DisplayNameFor(model => model.AttachmentFile.FileName)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.CreatedTime)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.CreatedByUser.FullName)
                </th>
                <th>
                    Role
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Subject)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Body)
                </th>
                <th></th>
            </tr>

            @foreach (var item in Model)
            {
                <tr>
                    <td>

                        @Html.DisplayFor(modelItem => item.AttachmentFile.FileName)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.CreatedTime)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.CreatedByUser.FullName)
                    </td>
                    <td>
                        @if (item.CreatedByUserId == User.Identity.GetUserId())
                        {
                            <span class="badge">Student</span>
                        }
                        else
                        {
                            <span class="badge alert-danger">Teacher</span>
                        }
                    </td>

                    <td>
                        @{ var TempSub = "";
                         if (item.Subject.Length > 20)
                         {
                             TempSub = item.Subject.Substring(0, 20) + " ...";
                         }
                         else
                         {
                             TempSub = item.Subject;
                         }
                        }
                        @TempSub
                        @*@Html.DisplayFor(modelItem => item.Subject)*@
                    </td>
                    <td>
                        @{ var TempBoby = "";
                         if (item.Body.Length > 20)
                         {
                             TempBoby = item.Body.Substring(0, 20) + "...";
                         }
                         else
                         {

                             TempBoby = item.Body;
                         }
                        }
                        @TempBoby
                        @*@Html.DisplayFor(modelItem => item.Body)*@
                    </td>
                    <td>
                        @*@Html.ActionLink("Edit", "Edit", "Document", null, new { @class = "btn btn-info btn-sm  glyphicon glyphicon-pencil " })*@
                        @Html.ActionLink("Details", "Details", "Document", new { id = item.DocumentID }, new { @class = "btn btn-success btn-sm  glyphicon glyphicon-pencil " })
                        @{
                if (User.Identity.GetUserId() == item.CreatedByUserId)
                {
                    @Html.ActionLink("Delete", "Delete", "Document", new { id = item.DocumentID }, new { @class = "btn btn-warning btn-sm  glyphicon glyphicon-pencil " })

                }
                else
                {
                    @Html.ActionLink("Delete", "Delete", "Document", new { id = item.DocumentID }, new { @class = "btn btn-warning btn-sm  glyphicon glyphicon-pencil hide", @disabled = "disabled" })

                }
                        }
                    </td>
                </tr>
            }

        </table>
    </div>
</div>
